package Test;

import java.io.File;
import org.junit.Test;
import static org.junit.Assert.*;
import Task25.Controller;

public class renameTest {

	@Test
	public void fileAbs() {
		String[] copyCommand = {"copy", "C:\\Test\\Test1\\1.txt", "C:\\Test\\Test1\\4.txt"};
		Controller.gui(copyCommand);
		String rename = "C:\\Test\\Test1\\newName.txt";
		String[] renameCommand = {"rename" , "C:\\Test\\Test1\\4.txt", rename};
		Controller.gui(renameCommand);
		assertTest(rename, "newName.txt");
		refresh(rename);
	}
	
	@Test
	public void folderAbs(){
		String[] copyCommand = {"copy", "C:\\Test\\Test3", "C:\\Test\\Test4"};
		Controller.gui(copyCommand);
		String rename = "C:\\Test\\newName";
		String[] renameCommand = {"rename" , "C:\\Test\\Test4", rename};
		Controller.gui(renameCommand);
		assertTest(rename, "newName");
		refresh(rename);
	}
	
	@Test
	public void fileRel(){
		String[] cdCommand = {"cd", "C:\\Test"};
		Controller.gui(cdCommand);
		String[] copyCommand = {"copy", "Test1\\1.txt", "Test1\\4.txt"};
		Controller.gui(copyCommand);
		String rename = "Test1\\newName.txt";
		String[] renameCommand = {"rename" , "Test1\\4.txt", rename};
		Controller.gui(renameCommand);
		assertTest("C:\\Test\\"+rename, "newName.txt");
		refresh("C:\\Test\\"+rename);
	}

	@Test
	public void folderRel() {
		String[] cdCommand = {"cd", "C:\\Test"};
		Controller.gui(cdCommand);
		String[] copyCommand = {"copy", "Test3", "Test4"};
		Controller.gui(copyCommand);
		String rename = "newName";
		String[] renameCommand = {"rename" , "Test4", rename};
		Controller.gui(renameCommand);
		assertTest("C:\\Test\\"+rename, "newName");
		refresh("C:\\Test\\"+rename);
	}

	private void assertTest(String path, String newName) {
		File rename = new File(path);
		assertEquals(rename.getName(), newName);
	}

	private void refresh(String path) {
		String[] command = { "del", path };
		Controller.gui(command);
	}
}
